<?php
	require_once 'db_connection.php';
	header("Content-Type:text/html;charset=UTF-8");
	class jsxx extends db_connection{
		function jsxx(){
			$this->con();
			$s = file_get_contents("./jsxx.csv");
			$s =iconv('GBK','UTF-8',$s);
			$array = explode(",",$s);
			$n = (count($array)-9)/8;
			$i=1;
			while($i<$n){
				$t = $i*8+1;
				$t1 = $t+6;
				$name = $array[$t1];
				if($array[$t]=='JS'){
					$sql = "INSERT INTO `teacher_info` (t_name) VALUES ('$name');";
					$this->db->query($sql);
				}
				$i++;
			}
		}
	}
	//$jsxx = new jsxx();
	class GetTearcherInfo extends db_connection{
		function GetTearcherInfo(){
			$this->con();
			$sql = "SELECT * FROM teacher_info";
			$s = $this->db->query($sql);
			foreach($s as $u){
				print_r($u);
				echo "<br />";
			}
		} 
	}
	//$xx = new GetTearcherInfo();
	class CourseList extends db_connection{
		function CourseList(){
			$s = file_get_contents("./kcqd.csv");
			$s =iconv('GBK','UTF-8',$s);
			$array = explode(",",$s);
			var_dump($array);
		}
	}
	//$list = new CourseList();
	class StudentInfo extends db_connection{
		function StudentInfo(){
			$this->con();
			$s = file_get_contents('./xkxx.csv');
			$s = iconv('GBK','UTF-8',$s);
			$array = explode(',',$s);
			$n = (int)(count($array)/11);
			//var_dump($array);
			for($i=2;$i<$n;$i++){
				$t = $i*11;
				$t1 = $t+1;
				$array[$t] = str_replace(array("'","\"","\r","\n"," "),"",$array[$t]);
				$sql = "SELECT * FROM student_info WHERE s_num = '$array[$t]'";
				$q = $this->db->query($sql);
				if(!$q->fetchColumn()){
					$sql = "INSERT INTO student_info (s_num,s_name) VALUES ('$array[$t]','$array[$t1]')";
					echo $sql;
					$this->db->exec($sql);
				}
			}
		}
	}
	//$student = new StudentInfo();
	class CourseInfo extends db_connection{
		function CourseInfo(){
			$this->con();
			$s = file_get_contents('./xkxx.csv');
			$s = iconv('GBK','UTF-8',$s);
			$array = explode(',',$s);
			$n = (int)(count($array)/12);
			for($i=2;$i<$n;$i++){
				$t = ($i*12)+3;
				$kch = $array[$t];
				$kxh = $array[$t+1];
				$kcm = $array[$t+3];
				$skxq = $array[$t+4];
				$skjc = $array[$t+5];
				$skdd = $array[$t+6];
				$skzc = '9'.$array[$t+7];
				//echo $kxh."<br />";
				$sql = "SELECT * FROM course_info WHERE c_num = '$kch' AND c_serialnum = '$kxh' ";
				$q = $this->db->query($sql);
				if(!$q->fetchColumn()){
					$sql = "INSERT INTO `sign_in`.`course_info` (`c_num`,`c_serialnum`,`c_name`,`c_address`,`c_week`,`c_hour`,`c_weeks`) VALUES ('$kch','$kxh','$kcm','$skdd','$skxq','$skjc','$skzc');";
					//echo $sql."<br />";
					$this->db->exec($sql);
				}
			}
			//var_dump($array); 
		}
	}
	//$course = new CourseInfo();
	class TeacherCourse extends db_connection{
		function TeacherCourse(){
			$this->con();
			$s = file_get_contents('./kcqd.csv');
			$s = iconv('GBK','UTF-8',$s);
			$array = explode(',',$s);
			$n = (int)(count($array)/5);
			for($i=1;$i<$n;$i++){
				$t = ($i*5)+1;
				$kch = $array[$t];
				$kxh = $array[$t+1];
				$kcm = $array[$t+2];
				$name = $array[$t+3];
				$sql = "SELECT * FROM course_info WHERE c_num = '$kch' AND c_serialnum = '$kxh' t_id = '0' ;";
				echo "<br />";
				$q = $this->db->query($sql);
				if($q){
					echo "<br />".$kch = $array[$t];
					echo "<br />".$kxh = $array[$t+1];
					echo "<br />".$kcm = $array[$t+2];
					echo "<br />".$name = $array[$t+3];
					// $id = $q->fetchColumn();
					// echo $id;
					// $sql = "SELECT t_id FROM teacher_info WHERE t_name = '$name';";
					// $q1 = $this->db->query($sql);
					// if($p = $q1->fetchAll()){
						// $flag = count($p);
						// if($flag=='1'){
							// $t_id = $p[0]['t_id'];
							// $sql = "UPDATE course_info SET t_id = '$t_id' WHERE c_id = '$id' ";
							// $s = $this->db->exec($sql);
							// if($s){
								// echo "OK";
							// }else{
								// echo "NO";
							// }	
						// }
					// }
				}else{
					// echo "<br />".$kch."+".$kxh;
				}
			}
			//var_dump($array);
		}
	}
	//$tea = new TeacherCourse();
	class ChoiceInfo extends db_connection{
		function ChoiceInfo(){
			$this->con();
			$s = file_get_contents("./xkxx.csv");
			$s =iconv('GBK','UTF-8',$s);
			$array = explode(",",$s);
			//var_dump($array);
			$n = (int)(count($array)/10);
			for($i=2;$i<$n;$i++){
				$t = ($i*10);
				$xh = $array[$t];
				$xh = trim($xh);
				$kch = $array[$t+3];
				$kxh = $array[$t+4];
				$sts = $array[$t+5];
				if($sts == "未定"){
					$s = 0;
				}else if($sts == "确定"){
					$s = 1;
				}
				$sql = "SELECT id FROM student_info WHERE s_num = '$xh';";
				$q = $this->db->query($sql);
				$s_id = $q->fetchColumn();
				$sql1 = "SELECT id FROM course_info WHERE c_num = '$kch' AND c_serialnum = '$kxh' ;";
				$q1 = $this->db->query($sql1);
				$c_id = $q1->fetchColumn();
				$sql2 = "INSERT INTO  `sign_in`.`sign_info` (`c_id`,`s_id`,`c_status`) VALUES ('$c_id','$s_id','$s');";
				$this->db->exec($sql2);
			}
		}
	}
	$choice = new ChoiceInfo();
?>
